package top.buluoluo.productservice.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.buluoluo.commoncore.domain.response.Result;
import top.buluoluo.productservice.dto.request.SpuPageRequest;
import top.buluoluo.productservice.dto.response.SkuDTO;
import top.buluoluo.productservice.dto.response.SpuDTO;
import top.buluoluo.productservice.dto.result.PageResult;
import top.buluoluo.productservice.service.ProductService;

import java.util.List;

@RestController
@RequestMapping("/product")
@Tag(name = "商品管理", description = "商品获取、添加、查看详情等接口")
public class ProductController {
    @Autowired
    private ProductService productService;
    @Operation(summary = "分页获取所有商品(spu表)", description = "根据商品种类id和品牌id获取商品(spu表)")
    @PostMapping("/getProducts")
    public Result<PageResult<SpuDTO>> getProducts(@RequestBody SpuPageRequest spuPageRequest) {
        return productService.getSpuPage(spuPageRequest);
    }
    @Operation(summary = "获取具体商品List(sku表)", description = "根据spuId获取不同规格的商品列表(sku表)")
    @GetMapping("/getDetailProducts/{spuId}")
    public Result<List<SkuDTO>> getDetailProducts(@PathVariable Long spuId) {
        return productService.getSkuBySpuId(spuId);
    }
    @Operation(summary = "获取具体商品(sku表)", description = "根据spuId获取不同规格的商品(sku表)")
    @GetMapping("/getSkuBySpuId/{skuId}")
    public Result<SkuDTO> getSkuBySpuId(@PathVariable Long skuId) {
        return productService.getSkuById(skuId);
    }
    @Operation(summary = "获取具体商品(spu表)", description = "根据spuId获取不同规格的商品(spu表)")
    @GetMapping("/getDetailProduct/{spuId}")
    public Result<SpuDTO> getDetailProduct(@PathVariable Long spuId) {
        return productService.getSpuBySpuId(spuId);
    }

}
